<?php

namespace app\common\service;

use app\common\service\Base;
use think\Db;
use function Symfony\Component\String\s;

/**
 * 成本管理-核价与补损跟进表
 */
class CostCheck extends Base
{

    public function check($type_name, $status, $ids)
    {
        switch ($status) {
            case 50: //发起核价到核价中
            case 100: //核价/补损完成
            case 150: //无需核价/补损
            case 200: //拒绝核价
                $remark=$status==150 ? '无需核价/补损' : '';
                $status= $status==150 ? 100 : $status;
                db('cost_check')->where([
                    ['id', 'in', $ids],
                ])->update([
                    'status' => $status,
                    'admin_id' => ADMIN_ID,
                    'admin_id_' . $status => ADMIN_ID,
                    'update_time_' . $status => time(),
                    'remark'=>$remark,
                    'update_time' => time(),
                ]);
                break;
            case 0: //重新发起核价
                db('cost_check')->where([
                    ['id', 'in', $ids],
                ])->update([
                    'status' => $status,
                    'return_num' => Db::raw('return_num+1'),
                    'admin_id' => ADMIN_ID,
                    'admin_id_' . $status => ADMIN_ID,
                    'update_time_' . $status => time(),
                    'remark'=>'',
                    'update_time' => time(),
                ]);
                break;
        }
        $this->addLog($ids, $status);
        return ['code' => 1, 'msg' => '成功'];
    }

    public function addLog($ids = [], $status)
    {
        $list = db('cost_check')->where([
            ['id', 'in', $ids],
        ])->select();
        $ins_ids = [];
        foreach ($list as $k => $v) {
            $ins_ids[] = db('cost_check_action_log')->insertGetId([
                'type' => $v['type'],
                'status' => $status,
                'return_num' => $v['return_num'],
                'stock_m_type' => $v['stock_m_type'],
                'order_material_id' => $v['order_material_id'],
                'order_id' => $v['order_id'],
                'client_ordernum' => $v['client_ordernum'],
                'remark' => $v['remark'],
                'admin_id' => ADMIN_ID,
                'update_time' => time(),
                'create_time' => time(),
            ]);
        }
        return $ins_ids;
    }

    /**
     * 1,跟据用户配置，查询要生成核价与补损 任务信息
     * 2，调用set_cost_check 生成核价与补损 任务
     * @author zhuguosen 905502314@qq.com
     * @date 2022/6/30
     */
    public function set_cost_check_all()
    {
        $config_0 = db('cost_check_config')->whereRaw("type=0")->order('id desc')->find();
        isset($config_0['id']) && $config_0 = json_decode($config_0['content'], true);
        $config_10000 = db('cost_check_config')->whereRaw("type=10000")->order('id desc')->find();
        isset($config_10000['id']) && $config_10000 = json_decode($config_10000['content'], true);
        $this->set_cost_check_select_1($config_0);
        $this->set_cost_check_select_2($config_0);
        $this->set_cost_check_select_3($config_0);
        return $this->set_cost_check_select_10000_all($config_10000);
//        return $this->sync_data();
    }

    //checkcloth_shrink--暂时不用加索引 因为用不到了。 stall_feed  加索引慢的处理  order_material_id
    public function sync_data()
    {
//        $page = 1;
//        for ($page = 1; $page < 1000000; $page++) {
//            $list = db('checkcloth_shrink2')
//                ->page($page)->limit(500)
//                ->select();
//            if (count($list) <= 0) {
//                return ['code' => 0, 'msg' => "结束了一共10*{$page} 个数据" . PHP_EOL];
//            }
//            db('checkcloth_shrink')->insertAll($list);
//        }
        $page = 1;
        for ($page = 1; $page < 1000000; $page++) {
            $list = db('stall_feed2 s2')
                ->field('s2.*')
                ->join('stall_feed s', 's2.id=s.id', 'left')
                ->whereRaw("s.id is null")
                ->page($page)->limit(500)
                ->select();
            if (count($list) <= 0) {
                return ['code' => 0, 'msg' => "结束了一共10*{$page} 个数据" . PHP_EOL];
            }
            db('stall_feed')->insertAll($list);
        }
        return ['code' => 0, 'msg' => "结束了一共10*{$page} 个数据" . PHP_EOL];
    }

    /**
     * 查询核价跟进》【面辅料】采购单价 高于 客户单价，生成任务
     * @author zhuguosen 905502314@qq.com
     * @date 2022/6/30
     */
    public function set_cost_check_select_1($orderIds=[0])
    {
        $config_0 = db('cost_check_config')->whereRaw("type=0")->order('id desc')->find();
        isset($config_0['id']) && $config_0 = json_decode($config_0['content'], true);
        $m_types = [];
        $type_percent = $config_0['type_percent']['1'];
        $type_percent = round($type_percent / 100, 4);
        foreach ($config_0['m_type']['1'] as $k => $v) {
            $m_types[] = $k;
        }
        if ($m_types == []) {
            return ['code' => 0, 'msg' => "核价跟进》面辅料，已经关闭"];
        }
            $where = [
                ['om.caigou_unitprice', '>', 0],
                ['om.customer_price', '>', 0],
                ['m.type', 'in', $m_types],
                ['o.status', 'in', [0, 1, 2]],
                ['om.order_id', 'in', $orderIds],
            ];
            $list = db('order_material om')
                ->field('om.mid,om.order_id,om.client_ordernum ,om.stock_m_type
                ,om.caigou_unitprice ,om.customer_price
                ,m.type
                ,cc.id as cc_id
                ')
                ->join('material m', 'om.material_id=m.id', 'left')
                ->join('cost_check cc', 'om.mid=cc.order_material_id and cc.type=1 ', 'left')
                ->join('order o', 'om.order_id=o.id', 'left')
                ->where($where)
                ->whereRaw("((om.caigou_unitprice-om.customer_price)/om.customer_price) >={$type_percent} ")
                ->whereRaw(" cc.id is null ")
                ->select();
            if (count($list) <= 0) {
                return ['code' => 0, 'msg' => "未找到符合条件的面辅核价数据" . PHP_EOL];
            }
            foreach ($list as $k => $v) {
                $res = $this->set_cost_check(1, $v['stock_m_type'], $v['client_ordernum'], $v['mid']);
            }
        return ['code' => 0, 'msg' => "共生成了".count($list)." 个面辅料核价数据" . PHP_EOL];
    }

    /**
     * 查询核价跟进》【单件用量】实际用量 大于 客服用量 %值（设置），生成任务
     * @author zhuguosen 905502314@qq.com
     * @date 2022/6/30
     */
    public function set_cost_check_select_2($orderIds=[0])
    {
        $config_0 = db('cost_check_config')->whereRaw("type=0")->order('id desc')->find();
        isset($config_0['id']) && $config_0 = json_decode($config_0['content'], true);
        $m_types = [];
        $type_percent = $config_0['type_percent']['2'];
        foreach ($config_0['m_type']['2'] as $k => $v) {
            $m_types[] = $k;
        }
        if ($m_types == []) {
            return ['code' => 0, 'msg' => "核价跟进》单件用量，已经关闭"];
        }

            $where = [
                ['om.caichuang_shiji_dosage', '>', 0],
                ['om.customer_dosage', '>', 0],
                ['m.type', 'in', $m_types],
                ['o.status', 'in', [0, 1, 2]],
                ['om.order_id', 'in', $orderIds],
            ];
            $list = db('order_material om')
                ->field('om.mid,om.order_id,om.client_ordernum ,om.stock_m_type
                ,om.caigou_unitprice ,om.customer_price
                ,m.type
                ,cc.id as cc_id
                ')
                ->join('material m', 'om.material_id=m.id', 'left')
                ->join('cost_check cc', 'om.order_id=cc.order_id and cc.type=2 ', 'left')
                ->join('order o', 'om.order_id=o.id', 'left')
                ->where($where)
                ->whereRaw("((om.caichuang_shiji_dosage-om.customer_dosage)/om.customer_dosage) >={$type_percent} ")
                ->whereRaw(" cc.id is null ")
                ->select();
            if (count($list) <= 0) {
                return ['code' => 0, 'msg' => "未找到符合条件的用量核价数据" . PHP_EOL];
            }
            foreach ($list as $k => $v) {
                $res = $this->set_cost_check(2, $v['stock_m_type'], $v['client_ordernum'], $v['mid']);
            }

        return ['code' => 0, 'msg' => "共生成了".count($list)."个 用量核价任务数据" . PHP_EOL];
    }

    /**
     * 查询核价跟进》【工艺染色】   后期整理时，2个表数据同步处理下。--暂时没处理。
     * @author zhuguosen 905502314@qq.com
     * @date 2022/6/30
     */
    public function set_cost_check_select_3($orderIds=[0])
    {
        $config_0 = db('cost_check_config')->whereRaw("type=0")->order('id desc')->find();
        isset($config_0['id']) && $config_0 = json_decode($config_0['content'], true);
        if (!isset($config_0['m_type']['3'])) {
            return ['code' => 0, 'msg' => "【工艺染色】关闭了，不能自动生成"];
        }
        $type_percent = $config_0['type_percent']['3'];

            $where = [
                ['o.status', 'in', [0, 1, 2]],
                ['ext.special_process_a_name', '=', '染色'],
                ['om.order_id', 'in', $orderIds],
            ];

            $list = db('order_ext ext')
                ->field('ext.special_process_a_name,ext.special_process_a_unitprice
                ,om.mid,om.order_id,om.client_ordernum ,om.stock_m_type
                ,om.caigou_unitprice ,om.customer_price
                ,m.type
                ,cc.id as cc_id
                ')
                ->join('order_material om', 'ext.order_id=om.order_id', 'left')
                ->join('material m', 'om.material_id=m.id', 'left')
                ->join('cost_check cc', 'ext.order_id=cc.order_id and cc.type=3 ', 'left')
                ->join('order o', 'ext.order_id=o.id', 'left')
                ->where($where)
                ->whereRaw("ext.special_process_a_unitprice >={$type_percent} ")
                ->group("ext.order_id")
                ->whereRaw(" cc.id is null ")
                ->select();
            if (count($list) <= 0) {
                return ['code' => 0, 'msg' => "未找到符合条件工艺染色核价的数据" . PHP_EOL];
            }

            foreach ($list as $k => $v) {
                $res = $this->set_cost_check(3, $v['stock_m_type'], $v['client_ordernum'], $v['mid']);
            }

        return ['code' => 0, 'msg' => "共生成了".count($list)."个 工艺染色核价任务数据" . PHP_EOL];
    }

    /**
     * 查询补损跟进》幅宽补损：实际幅宽， 小于VS 客户幅宽，生成任务---针对面里料
     * @author zhuguosen 905502314@qq.com
     * @date 2022/7/1
     */
    public function set_cost_check_select_10000($config_10000, $info)
    {
        $type_percent = $config_10000['type_percent']['10000'] / 100;
        $fabric_width = $info['fabric_width_once'] > 0 ? $info['fabric_width_once'] : $info['fabric_width'];
        if ($info['true_fabric_width'] <= 0 || $fabric_width <= 0) {
            return false;
        }
        if (($fabric_width - $info['true_fabric_width']) > 0) {
            if ($type_percent <= 0 || ($fabric_width - $info['true_fabric_width']) / $fabric_width >= $type_percent) {
                $res = $this->set_cost_check(10000, $info['stock_m_type'], $info['client_ordernum'], $info['mid']);
                return true;
            }
        }
        return false;
    }

    /**
     * 查询补损跟进》公斤补损：实际“缩水工序”的公斤 缩前重量，总和  小于VS 开单公斤 总和，生成任务
     * @return bool
     * @author zhuguosen 905502314@qq.com
     * @date 2022/7/2
     */
    public function set_cost_check_select_10001($config_10000, $info)
    {
        $type_percent = $config_10000['type_percent']['10001'] / 100;
        if ($info['osStat']['billing_caigou_kgcount'] <= 0 || count($info['cs_list']) <= 0) {
            return false;
        }
        //实际“缩水工序”的公斤 缩前重量
        $true_kgcount = 0;
        foreach ($info['cs_list'] as $k => $v) {
            if ($v['type'] == 2) {
                $true_kgcount += $v['weight_shrink'];
            }
        }
        if ($info['osStat']['billing_caigou_kgcount'] <= 0 || $true_kgcount <= 0) {
            return false;
        }
        //开单公斤  $info['osStat']['billing_caigou_kgcount']

        if (($info['osStat']['billing_caigou_kgcount'] - $true_kgcount) > 0) {
            if ($type_percent <= 0 || ($info['osStat']['billing_caigou_kgcount'] - $true_kgcount) / $info['osStat']['billing_caigou_kgcount'] >= $type_percent) {
                $res = $this->set_cost_check(10001, $info['stock_m_type'], $info['client_ordernum'], $info['mid']);
                return true;
            }
        }
        return false;
    }

    /**
     * 查询补损跟进》米数补损：实际“验布工序”的米数 缩前重量，总和  小于VS 开单米数 总和，生成任务
     * @return bool
     * @author zhuguosen 905502314@qq.com
     * @date 2022/7/2
     */
    public function set_cost_check_select_10002($config_10000, $info)
    {
        $type_percent = $config_10000['type_percent']['10001'] / 100;
        if ($info['osStat']['billing_caigou_count_feed'] <= 0 || count($info['cs_list']) <= 0) {
            return false;
        }
        //实际“缩水工序或验布工序”的米数
        $true_mi = 0;
        $true_mi_1 = 0;//验布工序
        $true_mi_2 = 0;//缩水工序
        foreach ($info['cs_list'] as $k => $v) {
            if ($v['type'] == 1) {
                $true_mi_1 += $v['length'];
            }
            if ($v['type'] == 2) {
                $true_mi_2 += $v['length'];
            }
        }
        if ($info['osStat']['billing_caigou_count_feed'] <= 0 || $true_mi_1 <= 0) {
            return false;
        }
        //开单公斤  $info['osStat']['billing_caigou_kgcount']
        if (($info['osStat']['billing_caigou_count_feed'] - $true_mi_1) > 0) {
            if ($type_percent <= 0 || ($info['osStat']['billing_caigou_count_feed'] - $true_mi_1) / $info['osStat']['billing_caigou_count_feed'] >= $type_percent) {
                $res = $this->set_cost_check(10002, $info['stock_m_type'], $info['client_ordernum'], $info['mid']);
                return true;
            }
        }
        return false;
    }


    /**
     * 查询补损跟进》公斤补损：实际“缩水工序”的公斤 缩前重量，总和  小于VS 开单公斤 总和，生成任务
     * @author zhuguosen 905502314@qq.com
     * @date 2022/7/1
     */
    public function set_cost_check_select_10000_all($orderIds=[0])
    {
        $config_10000 = db('cost_check_config')->whereRaw("type=10000")->order('id desc')->find();
        isset($config_10000['id']) && $config_10000 = json_decode($config_10000['content'], true);
        $m_types = [];
        $type_percent = $config_10000['type_percent']['10001'];
        foreach ($config_10000['m_type']['10001'] as $k => $v) {
            $m_types[] = $k;
        }
        if ($m_types == []) {
            return ['code' => 0, 'msg' => "补损跟进》幅宽补损，已经关闭"];
        }

        //1,stall_feed的信息sf.billing_caigou_kgcount ,sf.billing_caigou_count_feed
        $where = [
            ['m.type', 'in', $m_types],
            ['o.status', 'in', [0, 1, 2]],
            ['om.order_id', 'in', $orderIds],
        ];
        $list = db('order_material om')
            ->field("om.mid,om.order_id,om.client_ordernum ,om.stock_m_type
            ,m.type
           ")
            ->join('material m', 'om.material_id=m.id', 'left')
            ->join('cost_check cc', 'om.mid=cc.order_material_id and cc.type in (10000,10001,10002) ', 'left')
            ->join('order o', 'om.order_id=o.id', 'left')
//                ->whereRaw("
//                 (om.need_checkcloth =1 OR om.need_shrink=1 )
//                 and cc.id is null ")
            ->whereRaw(" cc.id is null ")
            ->where($where)
            ->select();
        $mids = [];
        foreach ($list as $k => $v) {
            $mids[] = $v['mid'];
        }
        if (count($mids) <= 0) {
            return ['code' => 0, 'msg' => "未找到需要 幅宽/公斤/米数 补损数据" . PHP_EOL];
        }
        $mids_str = implode(',', $mids);
        $sql = "SELECT om.mid,om.order_id,om.client_ordernum ,om.stock_m_type
            ,om.tiaoshu,om.true_fabric_width,om.fabric_width_once
            ,m.fabric_width
            ,group_concat(distinct sf.id ,',', sf.billing_caigou_kgcount,',', sf.billing_caigou_count_feed SEPARATOR ';') as sf_list
            ,group_concat(distinct cs.id ,',', cs.type,',', cs.length,',', cs.weight_shrink SEPARATOR ';') as cs_list
            FROM wx_order_material om
            LEFT JOIN wx_cost_check cc ON (om.mid=cc.order_material_id and cc.type in (10000,10001,10002))
            LEFT JOIN wx_stall_feed sf ON om.mid=sf.order_material_id
            LEFT JOIN wx_checkcloth_shrink cs  ON (om.order_id =cs.order_id and om.material_id=cs.material_id and cs.is_return=0)
            LEFT JOIN wx_material m ON om.material_id=m.id
            WHERE 1=1 
            and cc.id is null
            and om.mid in ({$mids_str})
            GROUP BY om.mid";
        $list = db()->query($sql);

        if (count($list) <= 0) {
            return ['code' => 0, 'msg' => "未找到需要 幅宽/公斤/米数 补损数据" . PHP_EOL];
        }
        $mids = [];
        foreach ($list as $k => $v) {
            $mids[] = $v['mid'];
            $list[$k]['sf_list'] = $osList = $this->_deal_sf_list($v['sf_list']);
            $list[$k]['cs_list'] = $osList_cs = $this->_deal_cs_list($v['cs_list']);
            $list[$k]['osStat'] = [
                'billing_caigou_kgcount' => array_sum(array_column($osList, 'billing_caigou_kgcount')),
                'billing_caigou_count_feed' => array_sum(array_column($osList, 'billing_caigou_count_feed')),
            ];
            $temp = $this->set_cost_check_select_10000($config_10000, $list[$k]);//幅宽
            if ($v['tiaoshu'] > 0 && $v['tiaoshu'] == count($list[$k]['sf_list'])
                && $v['tiaoshu'] == count($list[$k]['cs_list'])) {
                $temp = $this->set_cost_check_select_10001($config_10000, $list[$k]);//公斤
                $temp = $this->set_cost_check_select_10002($config_10000, $list[$k]);//米数
//                    if ($temp == true) {
//                        var_dump($list[$k]);
//                        die;
//                    }
            }
        }

        return ['code' => 0, 'msg' => "生成 幅宽/公斤/米数 补损数据完成" . PHP_EOL];
    }

    public function _deal_sf_list($feed_list)
    {
        if (trim($feed_list) == '') {
            return [];
        }
        $res = [];
        $list = explode(';', $feed_list);
        foreach ($list as $k => $v) {
            $temp = explode(',', $v);
            $res[] = [
                'id' => $temp[0],
                'billing_caigou_kgcount' => floatval($temp[1]),
                'billing_caigou_count_feed' => floatval($temp[2]),
            ];
        }
        return $res;
    }

    public function _deal_cs_list($feed_list)
    {
        if (trim($feed_list) == '') {
            return [];
        }
        $res = [];
        $list = explode(';', $feed_list);
        foreach ($list as $k => $v) {
            $temp = explode(',', $v);
            $res[] = [
                'id' => $temp[0],
                'type' => $temp[1],
                'length' => $temp[2],
                'weight_shrink' => $temp[3],
            ];
        }
        return $res;
    }

    //创建核价/补损跟进数据
    public function autoCreateCheckData($orderid,$checktype=[1,2,3,10000,10001,10002]){
        //type0核价跟进，1面辅料，2单件用量，3工艺染色，
        //[type] => 0 [type_percent] => Array ( [1] => 1 [2] => 4 [3] => 1 ) [m_type] => Array ( [1] => Array ( [fabric] => on [lining] => on [accessories] => on ) [2] => Array ( [lining] => on [other] => on ) [3] => on )
        //补损跟进  10000 副宽，10001公斤，10002米数
        //[type] => 10000 [type_percent] => Array ( [10000] => 0.05 [10001] => 0.02 [10002] => 0.05 )
        // [m_type] => Array ( [10000] => Array ( [fabric] => on [lining] => on ) [10001] => Array ( [fabric] => on [lining] => on ) [10002] => Array ( [fabric] => on [lining] => on ) )
        // [m_type] => Array ( [10000] => Array ( [fabric] => on [lining] => on ) [10002] => Array ( [fabric] => on [lining] => on ) )
        //入单确认之后，，对比 采购物料单价   客户物料单价
        //拉布完成确认用量，并生成数据，，判断是否要染色需要则生成核价数据；
        $priceConfig = db('cost_check_config')->whereRaw("type=0")->order('id desc')->find();
        isset($priceConfig['id']) && $priceConfig = json_decode($priceConfig['content'], true);
        $costConfig = db('cost_check_config')->whereRaw("type=10000")->order('id desc')->find();
        isset($costConfig['id']) && $costConfig = json_decode($costConfig['content'], true);

        //补损处理  --- 入单确认之后，，对比副宽、公斤、米数差异，，生成补损数据；
    }

    /**
     * 生成核价与补损 任务
     * @author zhuguosen 905502314@qq.com
     * @date 2022/6/30
     */
    public function set_cost_check($type = 0, $stock_m_type = 0, $client_ordernum_or_mid, $mid = 0, $ext = [])
    {
        switch ($type) {
            case 1:
            case 2:
            case 10000:
            case 10001:
            case 10002:
                switch ($stock_m_type) {
                    case 1:
                    case 0:
                        $order_info = db('order_material om')
                            ->field('om.mid,om.order_id,om.client_ordernum ,om.stock_m_type
                ,om.caigou_unitprice ,om.customer_price
                ,m.type
                ')
                            ->join('material m', 'om.material_id=m.id', 'left')
                            ->whereRaw("om.mid ={$mid} ")
                            ->find();
                        break;
                }
                if ($order_info == null) {
                    return ['code' => 10, 'msg' => ""];
                }
                //10,插入数据
                $insertGetId = db('cost_check')->insertGetId([
                    'type' => $type,
                    'status' => 0,
                    'return_num' => 0,
                    'stock_m_type' => $stock_m_type,
                    'order_material_id' => $order_info['mid'],
                    'order_id' => $order_info['order_id'],
                    'client_ordernum' => trim($order_info['client_ordernum']),
                    'remark' => '',
                    'info1' => floatval($ext['info1'] ?? 0),
                    'admin_id' => ADMIN_ID,
                    'admin_id_0' => ADMIN_ID,
                    'update_time_0' => time(),
                    'update_time' => time(),
                    'create_time' => time(),
                ]);
                $this->addLog([$insertGetId], 0);
                return ['code' => 0, 'msg' => ""];
                break;
            default:
                $order_info = db('order')->field('id,client_ordernum')->where(['client_ordernum' => $client_ordernum_or_mid])->find();
                if ($stock_m_type == 0 && !isset($order_info['id'])) {
                    return ['code' => 10, 'msg' => ""];
                }
                //10,插入数据
                $insertGetId = db('cost_check')->insertGetId([
                    'type' => $type,
                    'status' => 0,
                    'return_num' => 0,
                    'stock_m_type' => $stock_m_type,
                    'order_material_id' => $stock_m_type == 1 ? $client_ordernum_or_mid : 0,
                    'order_id' => $order_info['id'] ?? 0,
                    'client_ordernum' => $stock_m_type == 0 ? $client_ordernum_or_mid : '',
                    'remark' => '',
                    'info1' => floatval($ext['info1'] ?? 0),
                    'admin_id' => ADMIN_ID,
                    'admin_id_0' => ADMIN_ID,
                    'update_time_0' => time(),
                    'update_time' => time(),
                    'create_time' => time(),
                ]);
                $this->addLog([$insertGetId], 0);
                return ['code' => 0, 'msg' => ""];
                break;
        }
    }

    /**
     * 补损跟进 数据处理下
     * 幅宽补损  公斤补损  米数补损 信息处理
     * om.tiaoshu,om.true_fabric_width,om.fabric_width_once
     * ,group_concat(distinct sf.id ,',', sf.billing_caigou_kgcount,',', sf.billing_caigou_count_feed SEPARATOR ';') as sf_list
     * ,group_concat(distinct cs.id ,',', cs.type,',', cs.length,',', cs.weight_shrink SEPARATOR ';') as cs_list
     * @param $info
     * @author zhuguosen 905502314@qq.com
     * @date 2022/7/2
     */
    public function coverLossInfoDataDealWith($info)
    {
        $result = [
            10000 => [//幅宽补损
                'true_num' => 0,
                'user_num' => 0,
            ],
            10001 => [//公斤补损
                'true_num' => 0,
                'user_num' => 0,
            ],
            10002 => [//米数补损
                'true_num' => 0,
                'user_num' => 0,
            ],
        ];
        //0,幅宽补损
        $fabric_width = $info['fabric_width_once'] > 0 ? $info['fabric_width_once'] : $info['fabric_width'];
        $result[10000]['true_num'] = $info['true_fabric_width'];
        $result[10000]['user_num'] = $fabric_width;
        //1,公斤补损 实际“缩水工序”的公斤 缩前重量
        $info['cs_list'] = $this->_deal_cs_list($info['cs_list']);
        $info['sf_list'] = $this->_deal_sf_list($info['sf_list']);
        foreach ($info['cs_list'] as $k => $v) {
            if ($v['type'] == 2) {
                $result[10001]['true_num'] += $v['weight_shrink'];
            }
        }
        foreach ($info['sf_list'] as $k => $v) {
            $result[10001]['user_num'] += $v['billing_caigou_kgcount'];
        }
        //2,米数补损
        foreach ($info['cs_list'] as $k => $v) {
            if ($v['type'] == 1) {
                $result[10002]['true_num'] += $v['length'];
            }
        }
        foreach ($info['sf_list'] as $k => $v) {
            $result[10002]['user_num'] += $v['billing_caigou_count_feed'];
        }
        return $result;
    }
}